<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>transform | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>transform</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>transform</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/plugins/transform/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/10-plugins/16-transform.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">bower install moment-transform
</code></pre>

							</div>
<p><a href="javascript:window.open('http://nodejs.cn/s/24dRvp');" target="_blank" rel="nofollow"><code>moment-transform</code></a> &#x662F;&#x4E00;&#x4E2A;&#x901A;&#x8FC7;&#x6A21;&#x5F0F;&#x64CD;&#x4F5C;&#x65E5;&#x671F;&#x7684;&#x63D2;&#x4EF6;&#x3002;
&#x53EF;&#x4EE5;&#x5BF9; Moment &#x5B9E;&#x4F8B;&#x7684;&#x5404;&#x4E2A;&#x90E8;&#x5206;&#xFF08;&#x5C0F;&#x65F6;&#x3001;&#x6708;&#x4EFD;&#x7B49;&#xFF09;&#x4F7F;&#x7528;&#x57FA;&#x672C;&#x64CD;&#x4F5C;&#xFF08;&#x8BBE;&#x7F6E;/&#x6DFB;&#x52A0;/&#x51CF;&#x5C11;&#xFF09;&#x3002;</p>
<pre><code class="language-js">moment().transform(&apos;YYYY-MM-+01 00:00:00.000&apos;); // Tonight at midnight
moment().transform(&apos;14:30:00.000&apos;); // Today, 2:30 pm
moment().transform(&apos;YYYY-MM--30 00:00:00.000&apos;); // 30 days ago
</code></pre>
<p>&#x53EF;&#x9009;&#x7684;&#x53C2;&#x6570;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x6A21;&#x5F0F;&#x5E76;&#x5F3A;&#x5236;&#x4F7F;&#x7528;&#x4E25;&#x683C;&#x7684;&#x6A21;&#x5F0F;&#xFF08;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5728;&#x4F20;&#x5165;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x975E;&#x5B57;&#x6BCD;&#x5B57;&#x7B26;&#x4E0D;&#x662F;&#x5FC5;&#x9700;&#x7684;&#xFF09;&#x3002;</p>
<pre><code class="language-js">moment().transform(&apos;+01MMYYYY&apos;, &apos;DD/MM/YYYY&apos;, false); // Tomorrow, same time
moment().transform(&apos;+01MMYYYY&apos;, &apos;DD/MM/YYYY&apos;, true); // Invalid date
</code></pre>
<p>&#x793A;&#x4F8B;&#x5728;<a href="javascript:window.open('http://nodejs.cn/s/24dRvp');" target="_blank" rel="nofollow">&#x8FD9;&#x91CC;</a>&#xFF0C;&#x4ED3;&#x5E93;&#x5728;<a href="javascript:window.open('http://nodejs.cn/s/6rms54');" target="_blank" rel="nofollow">&#x8FD9;&#x91CC;</a>&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">bower install moment-transform
</code></pre>

							</div>
<p><a href="javascript:window.open('https://a----.github.io/moment-transform/');" target="_blank" rel="nofollow"><code>moment-transform</code></a> is a plugin that manipulated dates through patterns. You can use basic operations &#x2013;set/add/subtract&#x2013; on individual parts (hours, month, &#x2026;) of a Moment instance.</p>
<pre><code class="language-js">moment().transform(&apos;YYYY-MM-+01 00:00:00.000&apos;); // Tonight at midnight
moment().transform(&apos;14:30:00.000&apos;); // Today, 2:30 pm
moment().transform(&apos;YYYY-MM--30 00:00:00.000&apos;); // 30 days ago
</code></pre>
<p>Optional parameters lets you specify custom patterns and force strict pattern usage (non-alphabetic characters are not mandatory in passed string by default).</p>
<pre><code class="language-js">moment().transform(&apos;+01MMYYYY&apos;, &apos;DD/MM/YYYY&apos;, false); // Tomorrow, same time
moment().transform(&apos;+01MMYYYY&apos;, &apos;DD/MM/YYYY&apos;, true); // Invalid date
</code></pre>
<p>You can see it live <a href="javascript:window.open('https://a----.github.io/moment-transform/');" target="_blank" rel="nofollow">there</a> while the repository is <a href="javascript:window.open('https://github.com/A----/moment-transform');" target="_blank" rel="nofollow">here</a>.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>